package triannon.client.sprites;

import java.awt.Point;

import org.newdawn.slick.util.pathfinding.Mover;
import org.newdawn.slick.util.pathfinding.Path;
import org.newdawn.slick.util.pathfinding.Path.Step;

public abstract class LivingSprite extends AbstractSprite implements IHealth,
		ISelection, Mover {
	protected double health = 1d;
	protected boolean healthBarVisible = false;
	protected boolean selected = false;
	protected boolean preSelected = false;
	protected int goToX = -1;
	protected int goToY = -1;

	protected Path path = null;
	protected Step actStep = null;

	public LivingSprite(SpriteType layer, String key, Fraction fraction, int x,
			int y, double health) {
		super(layer, key, fraction);
		this.health = health;
		setLocation(x, y);
	}

	public LivingSprite(SpriteType layer, String key, Fraction fraction) {
		this(layer, key, fraction, 0, 0, 1d);
	}

	@Override
	public void setHealth(double health) {
		this.health = health;
	}

	@Override
	public double getHealth() {
		return health;
	}

	public Path getPath() {
		return path;
	}

	public void setPath(Path path) {
		this.path = path;
		if (path != null && actStep == null) {
			actStep = path.removeFirstStep();
		}
	}

	@Override
	public void setHealthBarVisible(boolean visible) {
		this.healthBarVisible = visible;
	}

	@Override
	public boolean isSelected() {
		return selected;
	}

	@Override
	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	@Override
	public boolean isPreSelected() {
		return preSelected;
	}

	@Override
	public void setPreSelected(boolean preSelected) {
		this.preSelected = preSelected;
	}

	public int getGoToX() {
		return goToX;
	}

	public int getGoToY() {
		return goToY;
	}

	public void setGoToX(int goToX) {
		this.goToX = goToX;
	}

	public void setGoToY(int goToY) {
		this.goToY = goToY;
	}

	public void setGoTo(Point point) {
		this.goToX = point.x;
		this.goToY = point.y;
	}
}
